#!/bin/sh

if [ -z $1 ];then
   hive_db=default
else
   hive_db=$1
fi

if [ -z $2 ];then
   create_time=`date  "+%Y-%m-%d %H-%M-%S"`
else
   create_time=$2
fi


hiveconfig=$(cat <<"EOF" /home/hdfs/parquet_shell/hive_parquet_scripts/hive.config
EOF
)

sql_suffix=$(cat <<EOF
INSERT INTO TABLE ${hive_db}.navinfo_parquet_0f38 PARTITION (part_time) SELECT time,latitude,longitude,height,direction,speed,routeStartTime,routeEndTime,driveCycleMileage,idlingMileage,paringRangeMileage,parkingIdleTime,brakeNumber,cumulativeMileage,brakingTime,vehicleEstimatedLoad,initialTotalFuelConsumption,terminationTotalFuelConsumption,cruiseRange,averageSpeedInterval,overSpeedTimes,idlingFuelConsumption,parkingIdleFuelConsumption,version,retransmissionPackets,protocolVersion,routeStopFlag,terminalId,routeStartMileage,routeStartFuelConsumption,routeStartLatitude,routeStartLongitude,routeStartHeight,routeStartDirection,routeEndMileage,routeEndFuelConsumption,routeEndLatitude,routeEndLongitude,routeEndHeight,routeEndDirection,routeIntegralMileage,routeGpsIntegralMileage,integralMileage,gpsIntegralMileage,vehicleTotalMileage,sharpCurveFrequency,sharpCurveMileage,routeIntegralFuelConsumption,routeTotalFuelConsumption,averageFuelConsumption,overSpeedDistance,overSpeedFuelConsumption,averageSpeedExcludeIdleTime,averageSpeedIncludeIdleTime,maxSpeed,parkingPowerOnTime,cityDrivingMileage,cityDrivingTime,cityDrivingFuelConsumption,ruralDrivingMileage,ruralDrivingTime,ruralDrivingFuelConsumption,ecoDrivingMileage,ecoDrivingTime,ecoDrivingFuelConsumption,upSlopeDrivingMileage,upSlopeDrivingTime,upSlopeDrivingFuelConsumption,downSlopeDrivingMileage,downSlopeDrivingTime,downSlopeDrivingFuelConsumption,levelRoadDrivingMileage,levelRoadDrivingTime,levelRoadDrivingFuelConsumption,coldEngineSharpDrivingMileage,coldEngineSharpDrivingTime,coldEngineSharpDrivingFuelConsumption,cruiseControlDrivingTime,cruiseControlDrivingFuelConsumption,engineOverSpeedDrivingMileage,engineOverSpeedDrivingTime,engineOverSpeedDrivingFuelConsumption,shiftGearsFrequency,sharpDownSpeedTime,sharpDownSpeedMileage,sharpDownSpeedFrequency,sharpUpSpeedTime,sharpUpSpeedMileage,sharpUpSpeedFrequency,sharpUpSpeedFuelConsumption,sharpStepOnAcceleratorMileage,sharpStepOnAcceleratorTime,sharpStepOnAcceleratorFuelConsumption,vehicleParkFrequency,vehicleStartFrequency,vehicleColdStartFrequency,fuelChargePercent,fuelChargeNumber,fuelLeakPercent,fuelLeakNumber,vehicleStartTime,vehicleStartFuelConsumption,acceleratorStabilityFrequency,acceleratorStabilityTime,instrumentFuelConsumption,clutchSwitchTime,maxEngineRotation,averageEngineRotation,averageAccelerator,speedRange01Mileage,speedRange01Time,speedRange01FuelConsumption,speedRange02Mileage,speedRange02Time,speedRange02FuelConsumption,speedRange03Mileage,speedRange03Time,speedRange03FuelConsumption,speedRange04Mileage,speedRange04Time,speedRange04FuelConsumption,speedRange05Mileage,speedRange05Time,speedRange05FuelConsumption,speedRange06Mileage,speedRange06Time,speedRange06FuelConsumption,speedRange07Mileage,speedRange07Time,speedRange07FuelConsumption,speedRange08Mileage,speedRange08Time,speedRange08FuelConsumption,speedRange09Mileage,speedRange09Time,speedRange09FuelConsumption,speedRange10Mileage,speedRange10Time,speedRange10FuelConsumption,speedRange11Mileage,speedRange11Time,speedRange11FuelConsumption,speedRange12Mileage,speedRange12Time,speedRange12FuelConsumption,exceedSpeedRangeMileage,exceedSpeedRangeTime,exceedSpeedRangeFuelConsumption,assistBrakeMileage,assistBrakeTime,fatigueDrivingFrequency,parkingStepOnAcceleratorTime,parkingStepOnAcceleratorFuelConsumption,engineWorkTime,drivingHandbrakeUseFrequency,drivingHandbrakeUseTime,drivingHandbrakeUseMileage,parkingIdleHandbrakeUseFrequency,parkingIdleHandbrakeUseTime,gear01UseRatio,gear01Mileage,gear01FuelConsumption,gear01Time,gear01Frequency,gear02UseRatio,gear02Mileage,gear02FuelConsumption,gear02Time,gear02Frequency,gear03UseRatio,gear03Mileage,gear03FuelConsumption,gear03Time,gear03Frequency,gear04UseRatio,gear04Mileage,gear04FuelConsumption,gear04Time,gear04Frequency,gear05UseRatio,gear05Mileage,gear05FuelConsumption,gear05Time,gear05Frequency,gear06UseRatio,gear06Mileage,gear06FuelConsumption,gear06Time,gear06Frequency,gear07UseRatio,gear07Mileage,gear07FuelConsumption,gear07Time,gear07Frequency,gear08UseRatio,gear08Mileage,gear08FuelConsumption,gear08Time,gear08Frequency,gear09UseRatio,gear09Mileage,gear09FuelConsumption,gear09Time,gear09Frequency,gear10UseRatio,gear10Mileage,gear10FuelConsumption,gear10Time,gear10Frequency,gear11UseRatio,gear11Mileage,gear11FuelConsumption,gear11Time,gear11Frequency,gear12UseRatio,gear12Mileage,gear12FuelConsumption,gear12Time,gear12Frequency,gear13UseRatio,gear13Mileage,gear13FuelConsumption,gear13Time,gear13Frequency,gear14UseRatio,gear14Mileage,gear14FuelConsumption,gear14Time,gear14Frequency,gear15UseRatio,gear15Mileage,gear15FuelConsumption,gear15Time,gear15Frequency,gear16UseRatio,gear16Mileage,gear16FuelConsumption,gear16Time,gear16Frequency,gearOtherUseRatio,gearOtherMileage,gearOtherFuelConsumption,gearOtherTime,gearOtherFrequency,engineSpeedRange01Mileage,engineSpeedRange01Time,engineSpeedRange01FuelConsumption,engineSpeedRange01UseRatio,engineSpeedRange01MileageRatio,engineSpeedRange01FuelConsumptionRatio,engineSpeedRange02Mileage,engineSpeedRange02Time,engineSpeedRange02FuelConsumption,engineSpeedRange02UseRatio,engineSpeedRange02MileageRatio,engineSpeedRange02FuelConsumptionRatio,engineSpeedRange03Mileage,engineSpeedRange03Time,engineSpeedRange03FuelConsumption,engineSpeedRange03UseRatio,engineSpeedRange03MileageRatio,engineSpeedRange03FuelConsumptionRatio,engineSpeedRange04Mileage,engineSpeedRange04Time,engineSpeedRange04FuelConsumption,engineSpeedRange04UseRatio,engineSpeedRange04MileageRatio,engineSpeedRange04FuelConsumptionRatio,engineSpeedRange05Mileage,engineSpeedRange05Time,engineSpeedRange05FuelConsumption,engineSpeedRange05UseRatio,engineSpeedRange05MileageRatio,engineSpeedRange05FuelConsumptionRatio,engineSpeedRange06Mileage,engineSpeedRange06Time,engineSpeedRange06FuelConsumption,engineSpeedRange06UseRatio,engineSpeedRange06MileageRatio,engineSpeedRange06FuelConsumptionRatio,exceedEngineSpeedRangeMileage,exceedEngineSpeedRangeTime,exceedEngineSpeedRangeFuelConsumption,exceedEngineSpeedRangeUseRatio,exceedEngineSpeedRangeMileageRatio,exceedEngineSpeedRangeFuelConsumptionRatio,carbonDioxideEmissions,routingCase,extendField01,extendField02,extendField03,extendField04,extendField05,extendField06,extendField07,extendField08,extendField09,extendField10,ecoDrivingTimeRatio,sharpStepOnAcceleratorFrequency,idlingFrequency,paringrangefrequency,${create_time}, originallat, originallng, part_time FROM ${hive_db}.navinfo_stage_0f38;
EOF
)

sql="${hiveconfig}${sql_suffix}"
############  execute begin   ###########
hive --hiveconf "tez.queue.name=hive" -S -e "$sql"
#echo $sql
